<template>
  <div>
    <el-button @click="submit" type="success" size="medium">保存</el-button>
    <div class="mt30 ft18"><i class="el-icon-star-on"></i>微信资料</div>
    <div class="pw100 flex_aj column">
      <r-list :ListRows="ListRows" :ListData="ListData"></r-list>
    </div>
    <div class="mt30 ft18"><i class="el-icon-star-on"></i>支付宝资料</div>
    <div class="pw100 flex_aj column">
      <r-list :ListRows="ListRowsAli" :ListData="ListDataAli"></r-list>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      id: '',
      ListRows: [
        [
          {
            label: '微信APPID',
            prop: 'wxAppId',
            type: 'input'
          },
          {
            label: '微信商户名称',
            prop: 'wxMchName',
            type: 'input'
          },
          {
            label: '微信商户ID',
            prop: 'wxMchId',
            type: 'input'
          },
          {
            label: '微信商户KEY',
            prop: 'wxMchKey',
            type: 'input'
          },
          {
            label: '微信商户密码',
            prop: 'wxSecrect',
            type: 'input'
          },
          {
            label: '微信退款证书',
            prop: 'wxCertPath',
            type: 'input',
            isDisabled: () => { return true },
            upload: {
              action: process.env.VUE_APP_URL + 'api/file/uploadCert',
              success: (res) => {
                this.ListData.wxCertPath = res.data.imgPath;
              },
              handleExceed: () => {
                this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
              }
            }
          },
          {
            label: '支付分ID',
            prop: 'serviceId',
            type: 'input'
          },
          {
            label: '公众号消息模版ID',
            prop: 'msgTemplateId',
            type: 'input'
          },
          {
            label: '微信私钥证书路径',
            prop: 'wxPemkeyPath',
            type: 'input',
            isDisabled: () => { return true },
            upload: {
              action: process.env.VUE_APP_URL + 'api/file/uploadCert',
              success: (res) => {
                this.ListData.wxPemkeyPath = res.data.imgPath;
              },
              handleExceed: () => {
                this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
              }
            }
          },
          {
            label: '商户API证书序列号',
            prop: 'wxSerialNo',
            type: 'input'
          },

        ]
      ],
      ListData: {
        wxAppId: '',
        wxMchName: '',
        wxMchId: '',
        wxMchKey: '',
        wxSecrect: '',
        wxCertPath: '',
        serviceId: '',
        msgTemplateId: '',
        wxPemkeyPath: '',
        wxSerialNo: ''
      },
      ListRowsAli: [
        [
          {
            label: '支付宝APPID',
            prop: 'aliAppId',
            type: 'input'
          },
          // {
          //     label: 'sellerlD',
          //     prop: 'weixinName',
          //   type:'input'
          // },
          {
            label: '私钥key',
            prop: 'privateKey',
            type: 'input'
          },
          {
            label: '公钥key',
            prop: 'publicKey',
            type: 'input'
          },

        ]
      ],
      ListDataAli: {
        aliAppId: '',
        privateKey: '',
        publicKey: ''
      }
    };
  },
  components: {},
  computed: {

  },
  mounted() {
    this.getData();
  },
  methods: {
    async submit() {
      if (this.id) {
        var res = await this.apis.pay_updata({
          id: this.id,
          wxMchName: this.ListData.wxMchName,
          wxMchId: this.ListData.wxMchId,
          wxAppId: this.ListData.wxAppId,
          wxMchKey: this.ListData.wxMchKey,
          wxSecrect: this.ListData.wxSecrect,
          wxCertPath: this.ListData.wxCertPath,
          serviceId: this.ListData.serviceId,
          msgTemplateId: this.ListData.msgTemplateId,
          wxPemkeyPath: this.ListData.wxPemkeyPath,
          wxSerialNo: this.ListData.wxSerialNo,

          aliAppId: this.ListDataAli.aliAppId,
          privateKey: this.ListDataAli.privateKey,
          publicKey: this.ListDataAli.publicKey
        });
      } else {
        var res = await this.apis.pay_add({
          wxMchName: this.ListData.wxMchName,
          wxMchId: this.ListData.wxMchId,
          wxAppId: this.ListData.wxAppId,
          wxMchKey: this.ListData.wxMchKey,
          wxSecrect: this.ListData.wxSecrect,
          wxCertPath: this.ListData.wxCertPath,
          serviceId: this.ListData.serviceId,
          msgTemplateId: this.ListData.msgTemplateId,
          wxPemkeyPath: this.ListData.wxPemkeyPath,
          wxSerialNo: this.ListData.wxSerialNo,

          aliAppId: this.ListDataAli.aliAppId,
          privateKey: this.ListDataAli.privateKey,
          publicKey: this.ListDataAli.publicKey
        });
      }


      this.$message({
        message: '操作成功',
        type: 'success'
      });
    },
    async getData() {
      var res = await this.apis.operatorPayInfo({
        id: this.$route.query.id
      });

      if (res.data) {
        var data = res.data || {};
        this.id = data.id;
        for (var key in data) {
          for (var key2 in this.ListData) {
            if (key == key2) {
              this.ListData[key2] = data[key];
            }
          }

          for (var key3 in this.ListDataAli) {
            if (key == key3) {
              this.ListDataAli[key3] = data[key];
            }
          }
        }
      }

    },
    subEditPassword() { },
    showMsgID() { }
  }
};
</script>
<style scoped lang='scss'>
</style>
